/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "TerrainCreateDialog.h"

#include "GameBuilder.h"
#include "TerrainTextureManager.h"

namespace PQBuilder
{
	TerrainCreateDialog::TerrainCreateDialog(QWidget *parent)
		: QDialog(parent),_ui(new Ui::TerrainCreateDialogUI)
	{
		_ui->setupUi(this);
		
		loadDiffuseTexIcons();
	}

	void TerrainCreateDialog::loadDiffuseTexIcons()
	{
		_ui->diffuseTexListWidget->clear();

		int cnt=TerrainTextureManager::getSingleton().getTextureCount();

		for (int i=0;i<cnt;++i){
			QFileInfo info=TerrainTextureManager::getSingleton().getTerrainFileInfo(i);

			QImage image;
			image.load(info.absoluteFilePath());

			QPixmap pixmap=QPixmap::fromImage(image);
			
			QListWidgetItem *item=new QListWidgetItem(QIcon(pixmap),info.fileName());
			item->setWhatsThis(info.fileName());
			item->setToolTip(info.fileName());

			_ui->diffuseTexListWidget->addItem(item);
		}
		
	}


	TerrainCreateDialog::~TerrainCreateDialog()
	{
		delete _ui;
	}

	void TerrainCreateDialog::accept()
	{
		
		int x=_ui->spinBoxSlotX->value();
		int y=_ui->spinBoxSlotY->value();

		int row=_ui->diffuseTexListWidget->currentRow();

		

		createTerrainSlot(x,y,row);

		
		QDialog::accept();
	}

	void TerrainCreateDialog::reject()
	{
		QDialog::reject();
	}

}
